import pymysql
import _thread
import urllib.request
import random

# do tender
def tender(postData,delay):
	url = "http://172.16.40.70:8008/ajax/borrows/tender"
	data = urllib.parse.urlencode(postData).encode(encoding='UTF8')
	#response = urllib.request.urlopen(url,data)
	print(data)

# search user to tender
db_connect = pymysql.connect("172.16.40.70","root","root","zhuangefang")
db = db_connect.cursor()
sql = "select * from hj_user"
borrow_id = 2
try:
	db.execute(sql)
	users = db.fetchall()
	i = 0
	for user in users:
		i += 1
		
		account = random.randint(100,999)
		account = account * 100

		res = {"action":"ed6495f7e3acf7e2658bed82c1bc4d7b","borrow_id":borrow_id,"card_type":1,"money_num":account,"pwd":"123456","user_id":user[0],"sort":i}
		print(res)
		try:
			_thread.start_new_thread(tender,(res,1))

		except:
			print("Error:无法启动线程")

except:
	print("Error:获取数据失败")
